package com.voltmao.webpro.utils.http;

import com.google.gson.internal.LinkedTreeMap;
import org.apache.http.client.methods.HttpPost;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class PostReportData {

    public Map<String, Object> getHeaderData() {
        return headerData;
    }

    private Map<String, Object> headerData = new LinkedTreeMap<>();          //报文头
    private Map<String, Object> requestParams = new LinkedTreeMap<>();       //参数信息
    private Map<String, String> cookies = new LinkedTreeMap<>();


    public String getOutStr() {
        return outStr;
    }

    public void setOutStr(String outStr) {
        this.outStr = outStr;
    }

    private String outStr;

    /**
     * 增加报文头的信息
     *
     * @param key
     * @param value
     */
    public void addHeaderInfo(String key, String value) {
        headerData.put(key, value);
    }

    /**
     * 增加报文头的信息
     *
     * @param key
     * @param value
     */
    public void addRequestParams(String key, String value) {
        requestParams.put(key, value);
    }

    public void addCookie(String key, String value) {
        cookies.put(key, value);
    }

    /**
     * @param httpPost
     */
    public void builderHttpPostHeader(HttpPost httpPost) {
        Set<String> keySet = headerData.keySet();
        Iterator<String> it = keySet.iterator();
        while (it.hasNext()) {
            String key = it.next();
            httpPost.setHeader(key, headerData.get(key) + "");
        }
    }

    public void builderHttpCookie(HttpPost httpPost) {
        StringBuilder stringBuilder = new StringBuilder();

        Set<String> keySet = cookies.keySet();
        Iterator<String> it = keySet.iterator();
        while (it.hasNext()) {
            String key = it.next();

            stringBuilder.append(key + "=\"" + cookies.get(key) + "\";");
        }

        System.out.println("_ai_=\"h1X218nUmu9Tzr0GUSd2kjhC1wdzDCxV8bVgHMqF3H0nrcXR+8JHNovgfZmQGmB6EZNYJ4TO7JuRY0YiOgyx164cXeh9bDW6NmX5BYqfTt5rYZjJMLIWHnorHSYZalaulCW29knsdzo=\"; _wcfl_=\"aWumapF+jJ8LTRtg9D0RK280QhWfznJ0\"; _ccode_=IWCIUA; _wcf_=\"4YXwxvESZzG8AqyLwaGMSncSiNd8QD6S16cxOMsRAcFRSFLy3G4n6M26060ogZvt9oVKSENswAJ95q3eUUvdUQ4BnZb1PGMhOl8FlkSWZmHb0sn7+2p1V0Wq1kygxO3AR7OfVxjcIPAj6/j0/xCkmg==\"");
        System.out.println(stringBuilder.toString());

        httpPost.setHeader("Cookie", stringBuilder.toString());


//            new BasicHeader("","");
//
//            BasicClientCookie basicClientCookie = new BasicClientCookie();
//            basicClientCookie.s
//            httpPost.addHeader();

    }

    public Map<String, Object> getRequestParams() {
        return requestParams;
    }

    public void setHeaderData(Map<String, Object> headerData) {
        this.headerData = headerData;
    }

    public void setRequestParams(Map<String, Object> requestParams) {
        this.requestParams = requestParams;
    }
}